package com.amoyhong.hongWhether.control;

import android.content.Context;
import android.content.SharedPreferences;

import com.amoyhong.hongWhether.MyApplication;
import com.orhanobut.logger.Logger;


/**
 * Created by Administrator on 2016/1/9.
 */
public class SharePreferenceManager {

    private static final String TAG = "SharePreferenceManager";

    public static final String NAME_FOR_SHAREPREFERENCE = "HONG_SHARE";

    public static final String KEY_FOR_LATITUDE = "latitude";
    public static final String KEY_FOR_LONGITUDE = "longitude";
    public static final String KEY_FOR_GE_LOCATION_NAME = "KEY_FOR_GE_LOCATION_NAME";
    public static final String KEY_FOR_WEATHER_LOCATION_NAME = "KEY_FOR_WEATHER_LOCATION_NAME";


    public static float getLatitude(){
        SharedPreferences sharedPreferences = MyApplication.getInstance().getSharedPreferences(NAME_FOR_SHAREPREFERENCE, Context.MODE_PRIVATE);
        return sharedPreferences.getFloat(KEY_FOR_LATITUDE,-1f);
    }


    public static float getLongitude(){
        SharedPreferences sharedPreferences = MyApplication.getInstance().getSharedPreferences(NAME_FOR_SHAREPREFERENCE, Context.MODE_PRIVATE);
        return sharedPreferences.getFloat(KEY_FOR_LONGITUDE,-1f);
    }

    public static String getGeLocationName(){
        SharedPreferences sharedPreferences = MyApplication.getInstance().getSharedPreferences(NAME_FOR_SHAREPREFERENCE, Context.MODE_PRIVATE);
        return sharedPreferences.getString(KEY_FOR_GE_LOCATION_NAME, "");
    }

    public static String getWeatherLocationName(){
        SharedPreferences sharedPreferences = MyApplication.getInstance().getSharedPreferences(NAME_FOR_SHAREPREFERENCE, Context.MODE_PRIVATE);
        return sharedPreferences.getString(KEY_FOR_WEATHER_LOCATION_NAME, "");
    }

    public static void saveLatitude(float latitude){
        SharedPreferences sharedPreferences = MyApplication.getInstance().getSharedPreferences(NAME_FOR_SHAREPREFERENCE, Context.MODE_PRIVATE);
        sharedPreferences.edit().putFloat(KEY_FOR_LATITUDE,latitude).commit();
    }

    public static void saveLongitude(float longitude){
        SharedPreferences sharedPreferences = MyApplication.getInstance().getSharedPreferences(NAME_FOR_SHAREPREFERENCE, Context.MODE_PRIVATE);
        sharedPreferences.edit().putFloat(KEY_FOR_LONGITUDE,longitude).commit();
    }

    public static void saveGeLocationName(String locationName){
        Logger.d("saveGeLocationName() called with: " + "locationName = [" + locationName + "]");
        SharedPreferences sharedPreferences = MyApplication.getInstance().getSharedPreferences(NAME_FOR_SHAREPREFERENCE, Context.MODE_PRIVATE);
        sharedPreferences.edit().putString(KEY_FOR_GE_LOCATION_NAME, locationName).commit();
    }

    public static void saveWeatherLocationName(String locationName){
        Logger.d("saveWeatherLocationName() called with: " + "locationName = [" + locationName + "]");
        SharedPreferences sharedPreferences = MyApplication.getInstance().getSharedPreferences(NAME_FOR_SHAREPREFERENCE, Context.MODE_PRIVATE);
        sharedPreferences.edit().putString(KEY_FOR_WEATHER_LOCATION_NAME, locationName).commit();
    }


}
